@attribute [Route(PageUrls.SystemPrompts)]
@attribute [Route("{culture?}" + PageUrls.SystemPrompts)]
@attribute [Authorize(Policy = AppFeatures.Management.ManageAiPrompt)]
@inherits AppPageBase


<AppPageData Title="@Localizer[nameof(AppStrings.SystemPromptsTitle)]"
             SubTitle="@Localizer[nameof(AppStrings.SystemPromptsSubTitle)]" />
<section>
    @if (isLoading)
    {
        <BitEllipsisLoading CustomSize="32" />
    }
    else if (systemPrompts is not null)
    {
        <BitPivot>

            @foreach (var systemPrompt in systemPrompts)
            {
                <BitPivotItem HeaderText="@systemPrompt.PromptKind.ToString()">
                    <BitSticky Top="5rem" Style="margin-bottom:8px">
                        <BitButton IconName="@BitIconName.Save" OnClick="WrapHandled(() => SaveChanges(systemPrompt))" AutoLoading>
                            @Localizer[nameof(AppStrings.Save)]
                        </BitButton>
                    </BitSticky>

                    <BitStack VerticalAlign="BitAlignment.Stretch" Horizontal>
                        <AuthorizeView Policy="@AppFeatures.Management.ManageAiPrompt">
                            <BitMarkdownEditor @bind-Value="systemPrompt.Markdown" Class="md-editor" />
                        </AuthorizeView>
                        <BitMarkdownViewer Markdown="@systemPrompt.Markdown" Class="md-viewer" />
                    </BitStack>
                </BitPivotItem>
            }

        </BitPivot>
    }
</section>